import os
from .log_config import loggerqa
from dotenv import dotenv_values
from app.utils.device import get_cuda_device_num

env_vars = dotenv_values(".env")

RERANKER_MODEL =env_vars["RERANKER_MODEL"] 
# Embedding model name
EMBEDDING_MODEL = env_vars["EMBEDDING_MODEL"] 

DEFAULT_MODEL_NAME=env_vars['DEFAULT_MODEL_NAME']

os.environ["OPENAI_API_BASE"] = env_vars['OPENAI_API_BASE']

os.environ["OPENAI_API_KEY"] =  env_vars['OPENAI_API_KEY']

os.environ["DEFAULT_MODEL_NAME"] =  env_vars['DEFAULT_MODEL_NAME']

os.environ['CUDA_VISIBLE_DEVICES']=env_vars['CUDA_VISIBLE_DEVICES'] if env_vars['CUDA_VISIBLE_DEVICES'] else '0'

EMBEDDING_DEVICE_NUM = get_cuda_device_num()
# print("EMBEDDING_DEVICE_NUM",EMBEDDING_DEVICE_NUM)
EMBEDDING_DEVICE_MAP={
    "ranker_model":"cuda" if  EMBEDDING_DEVICE_NUM <=1 else "cuda:0",
    "embedding_model":"cuda" if  EMBEDDING_DEVICE_NUM <=1 else "cuda:1"
}

# 知识库检索时返回的匹配内容条数
VECTOR_SEARCH_TOP_K = 5

# 知识检索内容相关度 Score, 数值范围约为0-1，如果为0，则不生效
VECTOR_SEARCH_SCORE_THRESHOLD = 0.4

loggerqa.info(f"""loading model config
embedding model name: {EMBEDDING_MODEL}
embedding device: {str(EMBEDDING_DEVICE_MAP)}
EMBEDDING_DEVICE_NUM:{EMBEDDING_DEVICE_NUM}
""")

# 文本分句长度
SENTENCE_SIZE = 400

# 是否开启中文标题加强，以及标题增强的相关配置
# 通过增加标题判断，判断哪些文本为标题，并在metadata中进行标记；
# 然后将文本与往上一级的标题进行拼合，实现文本信息的增强。
ZH_TITLE_ENHANCE = False

UPLOAD_ROOT_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),'uploads')